package com.sapient.DAO;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;


public class CommodityCreateDAO {
	static String url = "jdbc:oracle:thin:@10.207.60.85:1521/XE";
	static String username = "surv";
	static String password = "surv";

	public static boolean insertCommodity( String CommodityType,String CommodityClass,String lastupdateduser,String startDate,String endDate) 

	{
		
		String status="P";
		if(lastupdateduser.equals("admin"))
		{			
			status="A";
		}
		
		
		try {
			Class.forName("oracle.jdbc.driver.OracleDriver");

			Connection con= DriverManager.getConnection(url, username, password);

			Statement st=con.createStatement();

			String SQL1 = "select * from Commodity where commoditytype = '"+CommodityType+"'"; 
			ResultSet rs = st.executeQuery(SQL1);
			if(rs.next()){
				return false;
			}
			else{
				String query= "INSERT INTO Commodity(Commodityid,CommodityType,CommodityClass,StartDate,EndDate,lastupdateduser,lastupdateddate,flag,Status) " +
						"VALUES (commoditySeq.nextval,'"+CommodityType+"','"+CommodityClass+"',to_date('" +startDate+"','RR/MM/DD'),"+
						"to_date('" +endDate+"','RR/MM/DD'),'"+lastupdateduser+"',CURRENT_DATE,'N','"+status+"')";
				System.out.println(query);
				st.executeUpdate(query);
				st.close();                                                                       
				con.close(); 
			}
		}
		catch(Exception e)
		{
			System.out.println(" Error");
			e.printStackTrace();
		}
		return true;
		
	}


}
